# $Id: PKGBUILD 165520 2012-08-22 17:11:02Z dreisner $
# Maintainer: Dave Reisner <dreisner@archlinux.org>
# Contributor: Jaroslav Lichtblau <dragonlord@aur.archlinux.org>
# Contributor: Douglas Soares de Andrade
# Contributor: Roberto Alsina <ralsina@kde.org>

pkgname=varnish
pkgver=3.0.3
pkgrel=2
pkgdesc="High-performance HTTP accelerator"
arch=('i686' 'x86_64')
url="http://www.varnish-cache.org/"
license=('BSD')
depends=('gcc' 'libedit' 'pcre')
backup=('etc/conf.d/varnish'
        'etc/varnish/default.vcl')
install=$pkgname.install
options=('!libtool')
source=("http://repo.varnish-cache.org/source/$pkgname-$pkgver.tar.gz"
        "$pkgname.conf.d"
        "rc.$pkgname"
        varnish-vcl-reload
        varnish.service)
md5sums=('714310c83fdbd2061d897dacd3f63d8b'
         '3b563d2d9bd74a819fdb116d69d022f0'
         '40b4c83b3ad225ed2f4bd7e677fe41a2'
         '03196dee7fc68e75069393d52c370762'
         '1adf5282d111a9e00e99786045451016')

build() {
  cd "$pkgname-$pkgver"

  # disable JIT compilation for now, as it's crashy on VCL reload
  sed -i '/pcre_study/ s/PCRE_STUDY_JIT_COMPILE/0/' lib/libvarnish/vre.c

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var/lib

  make
}

package() {
  make -C "$pkgname-$pkgver" DESTDIR="$pkgdir" install

  # reload helper
  install -m755 "$srcdir/varnish-vcl-reload" "$pkgdir/usr/bin"

  # sysvinit
  install -Dm755 "$srcdir/rc.$pkgname" "$pkgdir/etc/rc.d/$pkgname"
  install -Dm644 "$srcdir/$pkgname.conf.d" "$pkgdir/etc/conf.d/$pkgname"

  # systemd
  install -Dm644 "$srcdir/$pkgname.service" "$pkgdir/usr/lib/systemd/system/$pkgname.service"

  # license
  install -Dm644 "$pkgname-$pkgver/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
